import { ref, reactive, watch } from 'vue'

import { R, Res } from '@/type/base'

import { merchantService } from '@/api'

import type { AttrList, Child } from '@/type/merchant/goodsInfo'

import { useStore } from '@/store'

export function useShoppingCar() {
  const store = useStore()
  const shoppingCarRef = ref()
  const shoppingCarData = reactive({
    goodsList: [],
    popupShow: false,
  })

  const openShoppingCar = (item: any) => {
    const itemList = store.useOrderStore.selectGoods
    if (itemList.length === 0) {
      uni.showToast({
        title: '您还未选购商品',
        icon: 'error',
      })
      return
    }
    shoppingCarData.goodsList = itemList as any
    shoppingCarRef.value.open()
  }

  watch(
    () => store.useOrderStore.selectGoods,
    () => {
      shoppingCarData.goodsList = store.useOrderStore.selectGoods as any
    },
    { deep: true }
  )

  return {
    shoppingCarData,
    shoppingCarRef,

    openShoppingCar,
  }
}
